//
//  LeaveMessageListViewController.m
//  家校互通
//
//  Created by 李赛 on 15/7/12.
//  Copyright (c) 2015年 姬鑫宇. All rights reserved.
//

#import "LeaveMessageListViewController.h"
#import "LeaveListTableViewCell.h"
#import "CoModel.h"
#import "NewsStyleOneTableViewCell.h"
@interface LeaveMessageListViewController ()<UITableViewDelegate,UITableViewDataSource,ConnectControlDelegate>{
    ConnectControl *connectCtr;
    
    NSMutableArray *sourceArray;
}

@end

@implementation LeaveMessageListViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    _contentTableView.delegate=self;
    _contentTableView.dataSource=self;
    
    sourceArray = [[NSMutableArray alloc] initWithCapacity:0];
    
    //    _contentTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    connectCtr = [ConnectControl showForView:self.view];
    connectCtr.delegate=self;
    
    if (connectCtr.superview!=nil && connectCtr.loading==NO)
    {
        [connectCtr setLoading:YES];
    }
    
    // Do any additional setup after loading the view.
}

- (void)connect{
    [CoModel getLeaves:^(BOOL result, NSArray *leavesArray, NSError *error) {
        [ConnectControl removeFromView:self.view];
        if (result) {
            sourceArray = [NSMutableArray arrayWithArray:leavesArray];
            [_contentTableView reloadData];
        }
    }];
}

#pragma mark -UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewsListModel *model = [sourceArray objectAtIndex:indexPath.section];
        
    NewsStyleOneTableViewCell *vCell=[tableView dequeueReusableCellWithIdentifier:@"NewsStyleOneTableViewCell" forIndexPath:indexPath];
    UIView *selectView=[[UIView alloc]initWithFrame:vCell.viewForHold.frame];
    selectView.backgroundColor=COLOR(240, 240, 240);
    vCell.selectedBackgroundView=selectView;
    [vCell setContentOfJiatiao:model];
    vCell.imgRedNood.hidden = YES;
    return vCell;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return sourceArray.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return nil;
}
#pragma mark -UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}
// Called after the user changes the selection.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    NewsListModel *model = [sourceArray objectAtIndex:indexPath.section];
    
    AskingForLeaveViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"AskingForLeaveViewController"];
    vc.title=@"请假条";
    vc.chartId = model.id;
    [_appDelegate.mainViewController.navigationController pushViewController:vc animated:YES];
    
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
